import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

// 这个数组中存放的就是所有路由配置对象
const routes = [
  {
    path: '/login',
    name: 'login',
    // 路由懒加载，只有当访问到这个路由时，才会去加载对应的这个组件
    component: () => import('@/views/Login/index'),
  },
  {
    path: '',
    name: 'layout',
    component: () => import('@/views/Layout/index'),
    children: [
      // 如果某个子路由配置的 path 为空字符串，那么就是默认子路由
      {
        path: '',
        name: 'home',
        component: () => import('@/views/Home/index'),
      },
      { path: 'qa', name: 'qa', component: () => import('@/views/QA/index') },
      {
        path: 'video',
        name: 'video',
        component: () => import('@/views/Video/index'),
      },
      { path: 'my', name: 'my', component: () => import('@/views/My/index') },
    ],
  },
  {
    path: '/search',
    name: 'search',
    component: () => import('@/views/Search/index'),
  },
]

const router = new VueRouter({
  routes,
})

export default router
